Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
The bonjour npm package is a zero-configuration networking library that allows for network discovery and service advertisement. It implements the multicast DNS (mDNS) protocol, commonly used for discovering services on a local network without the need for manual setup or configuration.
Service Advertising
This feature allows you to advertise network services such as HTTP servers, FTP servers, and more. The code sample demonstrates how to advertise an HTTP server on port 3000 using bonjour.
const bonjour = require('bonjour')();
// advertise an HTTP server on port 3000
bonjour.publish({ name: 'My Web Server', type: 'http', port: 3000 });
// Unpublish all services
bonjour.unpublishAll();
bonjour.destroy();
Service Discovery
This feature enables the discovery of services advertised on the local network. The code sample shows how to find all advertised HTTP services using bonjour.
const bonjour = require('bonjour')();
// browse for all HTTP services
bonjour.find({ type: 'http' }, function (service) {
console.log('Found an HTTP server:', service);
});
mdns is a more low-level package for multicast DNS service discovery. It provides similar functionalities to bonjour but requires more setup and configuration, making it less user-friendly for simple tasks but potentially more flexible for advanced use cases.
node-ssdp is a package that implements the Simple Service Discovery Protocol (SSDP). It is used primarily for discovering UPnP (Universal Plug and Play) devices. While it serves a similar purpose for service discovery, it uses a different protocol and is more focused on UPnP devices compared to the broader mDNS approach of bonjour.
A Bonjour/Zeroconf protocol implementation in pure JavaScript. Publish services on the local network or discover existing services using multicast DNS.
npm install bonjour
var bonjour = require('bonjour')()
// advertise an HTTP server on port 3000
bonjour.publish({ name: 'My Web Server', type: 'http', port: 3000 })
// browse for all http services
bonjour.find({ type: 'http' }, function (service) {
console.log('Found an HTTP server:', service)
})
var bonjour = require('bonjour')([options])
The options
are optional and will be used when initializing the
underlying multicast-dns server. For details see the multicast-dns
documentation.
var service = bonjour.publish(options)
Publishes a new service.
Options are:
name
(string)host
(string, optional) - defaults to local hostnameport
(number)type
(string)subtypes
(array of strings, optional)protocol
(string, optional) - udp
or tcp
(default)txt
(object, optional) - a key/value object to broadcast as the TXT
recordIANA maintains a list of official service types and port numbers.
bonjour.unpublishAll([callback])
Unpublish all services. The optional callback
will be called when the
services have been unpublished.
bonjour.destroy()
Destroy the mdns instance. Closes the udp socket.
var browser = bonjour.find(options[, onup])
Listen for services advertised on the network. An optional callback can
be provided as the 2nd argument and will be added as an event listener
for the up
event.
Options (all optional):
type
(string)subtypes
(array of strings)protocol
(string) - defaults to tcp
txt
(object) - passed into dns-txt
module contructor. Set to { binary: true }
if you want to keep the TXT records in binaryvar browser = bonjour.findOne(options[, callback])
Listen for and call the callback
with the first instance of a service
matching the options
. If no callback
is given, it's expected that
you listen for the up
event. The returned browser
will automatically
stop it self after the first matching service.
Options are the same as given in the browser.find
function.
Event: up
Emitted every time a new service is found that matches the browser.
Event: down
Emitted every time an existing service emmits a goodbye message.
browser.services
An array of services known by the browser to be online.
browser.start()
Start looking for matching services.
browser.stop()
Stop looking for matching services.
browser.update()
Broadcast the query again.
Event: up
Emitted when the service is up.
Event: error
Emitted if an error occurrs while publishing the service.
service.stop([callback])
Unpublish the service. The optional callback
will be called when the
service have been unpublished.
service.start()
Publish the service.
service.name
The name of the service, e.g. Apple TV
.
service.type
The type of the service, e.g. http
.
service.subtypes
An array of subtypes. Note that this property might be null
.
service.protocol
The protocol used by the service, e.g. tcp
.
service.host
The hostname or ip address where the service resides.
service.port
The port on which the service listens, e.g. 5000
.
service.fqdn
The fully qualified domain name of the service. E.g. if given the name
Foo Bar
, the type http
and the protocol tcp
, the service.fqdn
property will be Foo Bar._http._tcp.local
.
service.txt
The TXT record advertised by the service (a key/value object). Note that
this property might be null
.
service.published
A boolean indicating if the service is currently published.
MIT
FAQs
A Bonjour/Zeroconf implementation in pure JavaScript
The npm package bonjour receives a total of 2,427,336 weekly downloads. As such, bonjour popularity was classified as popular.
We found that bonjour demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.